<?php
/*
* Kusht Mud.
* ----
* The MIT License
* Copyright (c) 2010 Andrew Tutt
* ----
*/

/* Equipment Class
*
*  These are the main method of combat in the game
*/

/* We have some options here because we have done such a good job of abstraction.
*  We could make our items totally straightforward. 
*  Or we could make them really interesting, by screwing with their base
*  stats in all kinds of interesting ways. But that of course requires that we
*  give them some interesting base states. They have to be non-enumerable (we have
*  flags for that). So armor class, damage modifier...and...? 
*  rate of wear, critical hits, variability across items, tweakability (max stats)
*  anything else...? Weapon set (can be determined by script on vnums though)...
*  
*/

class Equipment extends Item {	
	// If you need ExtraDescription, write a MetaText and link to it using Markup
	// Affects inherited from BaseObject.
	// Weight inherited from BaseObject.
	
	// SET IN ALL_FLAGS
	// item_type: Set in All_Flags
	// wear_location: Set in All_Flags
	
	// Base stats
	public $avg_wear_rate; 				// how quickly does it wear out? (increases fragility after 10 hits? 100 hits?)
	public $avg_fragility; 				// How likely is it to break at random? (1 in 1000 or 1 in 100 etc.)
	public $avg_ac;						// Armor class
	public $avg_dmg;					// how much damage it does
	public $avg_speed;					// How fast does it strike?
	public $avg_tweakability; 			// How easily is it tweaked? (0-100)
	public $avg_max_dmg;				// how much better can it get? (in the avg case)
	public $avg_max_ac;					// how much better can it get? (in the avg base)
	public $avg_max_attack_rate;		// The fastest it can get (in the avg case)
	
	// The Instanced Values
	public $wear_rate;
	public $fragility;
	public $ac;
	public $dmg;
	public $speed;
	public $tweakability;
	public $max_dmg;
	public $max_ac;
	public $max_attack_rate;
	
	// Create a unique instance of this Equipment
	function generate() {
		$this->wear_rate		= $this->rollPosNrm($this->avg_wear_rate);
		$this->fragility		= $this->rollPosNrm($this->avg_fragility);
		$this->ac				= bound_between_limits(-10, $this->rollNrm($this->avg) , 10);
		$this->dmg				= $this->rollPosNrm($this->avg_dmg);
		$this->attack_rate		= $this->rollPosNrm($this->avg_speed);  // Speed is measured in Hz
		$this->tweakability		= bound_between_limits(0, $this->rollNrm($this->avg_tweakability) , 1);
		$this->max_dmg			= $this->rollPosNrm($this->avg_max_dmg);
		$this->max_ac			= bound_between_limits(-10, $this->rollNrm($this->avg_max_ac) , 10);
		$this->max_attack_rate	= $this->rollPosNrm($this->avg_max_speed);
		
		if($this->max_dmg < $this->dmg) 						{ $this->max_dmg = $this->dmg;							}
		if($this->max_ac > $this->ac) 							{ $this->max_ac = $this->ac; 							}
		if($this->avg_max_attack_rate < $this->max_attack_rate) { $this->max_attack_rate = $this->avg_max_attack_rate; 	}
	}
	
	function rollPosNrm($avg) {
		return .55666*$avg+.55666*$avg*nrmRandAbs();
	}
	
	function rollNrm($avg) {
		return $avg+$avg*nrmRand();
	}
	
	function rollUni($avg) {
		return $avg*uRand();
	}
}

?>